import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
import Home from 'pages/home/Home' // 首页
import MailList from 'pages/mailList/MailList' // 通讯录
import MySet from 'pages/myset/MySet' // 我的设置
import MyDetail from 'pages/mydetail/MyDetail' // 我的个人中心
import MyApplication from 'pages/myApplication/MyApplication' // 我的申请
import MyApplicationDetail from 'pages/myApplicationDetail/MyApplicationDetail' // 我的申请详情
import Apply from 'pages/apply/Apply' // 我的申请--申请
// import ErrorPage from 'pages/error/ErrorPage' // 404页面
// import MyTask from 'pages/myTask/MyTask' Apply
Vue.use(Router)
const VueRouter = new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    {
      path: '/mailList',
      name: 'mailList',
      component: MailList
    },
    {
      path: '/mySet',
      name: 'mySet',
      component: MySet
    },
    {
      path: '/myDetail',
      name: 'myDetail',
      component: MyDetail
    },
    {
      path: '/myApplication',
      name: 'myApplication',
      component: MyApplication
    },
    {
      path: '/myApplicationDetail',
      name: 'myApplicationDetail',
      component: MyApplicationDetail
    },
    {
      path: '/apply',
      name: 'apply',
      component: Apply
    },
    {
      path: '*',
      component: Home,
      name: 'home',
      meta: {
        title: '页面没找到'
      }
    }
  ]
})

VueRouter.beforeEach((to, from, next) => {
  // // 设置导航状态
  let routerName = to.name
  // // this.$store.dispatch('changeTabName', routerName)
  // this.a.methods.changeTabName(routerName)
  store.commit('changeTabName', routerName)
  next()
  // if (routerName === 'myApplicationDetail') {
  //   next({
  //     name: 'myApplicationDetail',
  //     params: to.params
  //   })
  //   next()
  // } else {
  //   next()
  // }
})

// afterEach
// VueRouter.afterEach((to, from, next) => {
//   // do something
//   // next()
// })

export default VueRouter
